//
//  UIBarbuttonItem+Extension.swift
//  mySina
//
//  Created by 刘莹 on 2016/11/12.
//  Copyright © 2016年 liuying. All rights reserved.
//

import UIKit
extension UIBarButtonItem{

    //分类中不能声明指定的构造函数
    convenience init(title:String = "", imageName:String?,target:Any?,action:Selector?){
        let btn = UIButton()
        
        //文字
        btn.setTitle(title, for: .normal)
        btn.setTitleColor(UIColor.darkGray, for: .normal)
        btn.setTitleColor(UIColor.orange, for: .highlighted)
        btn.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        //图片
        if let imag = imageName{
            
        btn.setImage(UIImage(named:imag), for: .normal)
        btn.setImage(UIImage(named:imag+"_highlighted"), for: .highlighted)
        }
        if let ac = action{
        
            btn.addTarget(target, action: ac, for: .touchUpInside)
        }
        
        btn.sizeToFit()
    
        self.init()
        self.customView = btn
    }
    
}
